package cn.iocoder.yudao.module.todo.service.tasksexecutors;

import cn.iocoder.yudao.module.todo.controller.admin.tasks.vo.TasksExecutorsPageReqVO;
import cn.iocoder.yudao.module.todo.controller.admin.tasks.vo.TasksExecutorsSaveReqVO;
import cn.iocoder.yudao.module.todo.dal.dataobject.tasks.TasksDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fhs.core.trans.anno.Trans;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;

import java.util.*;

import cn.iocoder.yudao.module.todo.dal.dataobject.tasksexecutors.TasksExecutorsDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.todo.dal.mysql.tasksexecutors.TasksExecutorsMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.todo.enums.ErrorCodeConstants.*;

/**
 * 待办任务执行者 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class TasksExecutorsServiceImpl implements TasksExecutorsService {

    @Resource
    private TasksExecutorsMapper tasksExecutorsMapper;

    @Override
    public String createTasksExecutors(TasksExecutorsSaveReqVO createReqVO) {
        // 插入
        TasksExecutorsDO tasksExecutors = BeanUtils.toBean(createReqVO, TasksExecutorsDO.class);
        tasksExecutorsMapper.insert(tasksExecutors);
        // 返回
        return tasksExecutors.getTaskId();
    }

    @Override
    public void updateTasksExecutors(TasksExecutorsSaveReqVO updateReqVO) {

    }

    @Override
    @Transactional
    public void bulkUpdateTasksExecutors(List<TasksExecutorsSaveReqVO> updateReqVO) {
        // 校验存在
//        validateTasksExecutorsExists(updateReqVO.getId());
        // 更新
        List<TasksExecutorsDO> updateObj = BeanUtils.toBean(updateReqVO, TasksExecutorsDO.class);
        tasksExecutorsMapper.updateById(updateObj);
    }

    @Override
    public void deleteTasksExecutors(String id) {
        // 校验存在
        validateTasksExecutorsExists(id);
        // 删除
        tasksExecutorsMapper.deleteById(id);
    }

    private void validateTasksExecutorsExists(String id) {
        if (tasksExecutorsMapper.selectById(id) == null) {
            throw exception(TASKS_PARTICIPANTS_NOT_EXISTS);
        }
    }

    @Override
    public TasksExecutorsDO getTasksExecutors(String id) {
        return tasksExecutorsMapper.selectById(id);
    }

    @Override
    public PageResult<TasksExecutorsDO> getTasksExecutorsPage(TasksExecutorsPageReqVO pageReqVO) {
        return tasksExecutorsMapper.selectPage(pageReqVO);
    }

}